﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web;
using System.IO;


namespace weclever.Navigation
{
    class WebClientNavigation : IPageCommunication
    {
        WebCookieClient wc = null;

        public WebClientNavigation()
        {
            wc = new WebCookieClient();                      
        }

        public string NavigateToURL(string url)
        {
            string htmlContent = "";
            try
            {
                Stream data = wc.OpenRead(new Uri(url));

                // Retrive the text
                StreamReader reader = new StreamReader(data);
                htmlContent = reader.ReadToEnd();
            }
            catch(Exception e)
            {
                Console.Write(e.Message);
            }
            return htmlContent;
        }


        public bool DownloadFile(string url, string fileName)
        {
            try
            {
                wc.DownloadFile(url, fileName);
            }
            catch
            {
                return false;
            }
            return true;
        }
    }
}
